﻿using System;
using System.Collections.Generic;
using System.IO;
using ProjScan.Config;
using ProjScan.RecordManager;
using ProjScan.ScanGUI;
using ProjScan.ScanRule;
using ProjScan.ScanRule.Attr;
using ProjScan.Tools;
using UnityEngine;

namespace ProjScan.Modules
{
	// Token: 0x02000303 RID: 771
	internal class BasicAssetsCheckModule : BaseModules<BasicAssetsCheckModule, BasicAssetsCheckConfig>
	{
		// Token: 0x0600123F RID: 4671 RVA: 0x00054C50 File Offset: 0x00052E50
		public override void Run(StreamWriter rulesSw, StreamWriter thresSw)
		{
			ToolsHelper.ShowProgressBar("Basic Assets Check", "Initializing...", 0.01f, false);
			this.Init();
			this.LoadRules(LoadMode.Check);
			bool flag = this.baseRules_Check == null || this.baseRules_Check.Count == 0;
			if (flag)
			{
				ScanLog.Instance.LogInfo("基本资源检测运行失败：相关规则全部关闭");
				this.Close();
			}
			else
			{
				this.rulesSw = rulesSw;
				this.thresSw = thresSw;
				this.InitRules(100);
				RecordManagerFactory.Instance.RecordRuleInit(this.recordRules_Check);
				try
				{
					RecordManagerFactory.Instance.PrepareAssets();
				}
				catch (Exception ex)
				{
					string str = "BasicAssetsCheckModule发生异常：";
					Exception ex2 = ex;
					Debug.LogError(str + ((ex2 != null) ? ex2.ToString() : null));
					this.Close();
					this.DeleteOutputFiles();
					Singleton<ScanOverviewManager>.Instance.SetModulesRunError("Basic_Assets_Check");
					return;
				}
				for (int i = 0; i < this.recordRules_Check.Count; i++)
				{
					RecordRule recordRule = this.recordRules_Check[i];
					ToolsHelper.ShowProgressBar(" Scan: output data", string.Format("Scan:{0}({1}/{2})", recordRule.GetType().Name, i + 1, this.recordRules_Check.Count), 0.5f * (float)(i + 1) / (float)this.recordRules_Check.Count, false);
					recordRule.OutputData(false);
					recordRule.OutputDetailData();
					recordRule.DumpToRuleCSV(ref this.rulesSw);
					recordRule.DumpToThresCSV(ref this.thresSw);
				}
				RecordManagerFactory.Instance.OutPutScanScr();
				RecordManagerFactory.Instance.Close();
				this.Close();
			}
		}

		// Token: 0x06001240 RID: 4672 RVA: 0x00054E10 File Offset: 0x00053010
		public override void Init()
		{
			this.ruleAttr = typeof(BasicAssetsRuleAttr);
			this.config = (Singleton<ConfigMgr>.Instance.GetConfig<BasicAssetsCheckConfig>() as BasicAssetsCheckConfig);
			bool flag = this.baseRules_Check == null;
			if (flag)
			{
				this.baseRules_Check = new List<BaseRule>();
			}
			else
			{
				this.baseRules_Check.Clear();
			}
			this.recordRules_Check.Clear();
			this.globalRules_Check.Clear();
			RecordManagerFactory.Instance.Init();
		}

		// Token: 0x06001241 RID: 4673 RVA: 0x00008874 File Offset: 0x00006A74
		public override void Close()
		{
			ScanLog.Instance.LogInfo("Basic_Assets_Check Done.");
			Debug.Log("Basic_Assets_Check Done.");
		}
	}
}
